$(window).load(function(){
    
    // ieCheck
    var ie = false;
    var aniButtonDuration = 350;
    
    if($.browser.msie && $.browser.version<9){
        aniButtonDuration = 0;
        ie = true;
    }
    
    //resize
   	var mainDIV = $('.main');
    $(window).resize(function()
    {
       resizeContent(500); 
    });
    
    function resizeContent(_animationSpeed){
        var window_H = $(window).height() - 144;
        var mainDIV_H = 720;
         
        if (window_H > mainDIV_H) {
			mainDIV.stop().animate({marginTop:~~((window_H - mainDIV_H)/2)}, _animationSpeed, 'easeOutCubic');	
		} else {
			mainDIV.stop().animate({marginTop:0}, _animationSpeed, 'easeOutCubic');	
		}
    }
    
    resizeContent(0);
    
    
    $(".slider").jCarouselLite({
        btnNext:'#controls .next',
        btnPrev:'#controls .prev',
        easing: 'easeOutSine',
        speed: 300,
        visible: 3
    });
    
    $('#controls .prev, #controls .next, #content > span a, #icon1, #icon2, #icon3, #icon4, #icon5, #icon6, #icon7')
	.sprites({
		method:'simple',
		duration:400,
		easing:'easeOutQuint',
		hover:true
	})
    
    
    $('.slider a').fancybox({
        'overlayColor'  :   '#fff',
        'transitionIn'	:	'elastic',
       	'transitionOut'	:	'elastic',
    	'speedIn'		:	500, 
    	'speedOut'		:	300
     });
     $('#fancybox-overlay').css({minWidth:$('body').css("min-width")})
     
     

    $('.slider li a span').animate({opacity:0}, 0);
     
    $('.slider li a').hover(function()
    {
        $(this).stop().animate({color:'#fff'}, 350,'easeOutCubic');					   
        $(this).find('span').stop().animate({opacity:1}, aniButtonDuration,'easeOutCubic');					   
    }, function(){
    	$(this).stop().animate({color:'#000'}, 350,'easeOutCubic');
         $(this).find('span').stop().animate({opacity:0}, aniButtonDuration,'easeOutCubic');						   
    })
    
	/////////////////////////////////////////////////////////////////////////// 
    //                           content switch                              //
    ///////////////////////////////////////////////////////////////////////////
    
    var content=$('#content'),
        nav=$('.menu'),
        header = $('.main header');
        
    if(!ie){
        $('#menu > li > a b').animate({scale:0}, 0);
    } else {
        $('#menu > li > a b').css({display:'none'});
    }
   
    
   
    nav.navs({
		useHash:true,
        defHash:'#!/page_home',
		hoverIn:function(li){
		    if(!ie){
                $('>a b',li).stop().animate({scale:1}, 250, 'easeOutQuint');
            } else {
                $('>a b',li).stop().css({display:'block'});
            }
		    $('>a span',li).stop().animate({color:'#000', fontSize:'40px'}, 150,'easeOutSine').animate({fontSize:'29px'}, 150, 'easeOutCubic');				   
		},
		hoverOut:function(li){
		    if(!ie){
		        $('>a b',li).stop().animate({scale:0}, 250, 'easeOutQuint');
            } else {
                $('>a b',li).stop().css({display:'none'});
            }
            $('>a span',li).stop().animate({color:'#fff', fontSize:'20px'}, 100,'easeOutSine').animate({fontSize:'29px'}, 150, 'easeOutCubic');
		}				
    })	
    
    content.tabs({
		preFu:function(_)
        {
            content.css({top:$(window).height()/2, display:'none'})
			_.li.css({display:'none', top:'510px'});			
		}
		,actFu:function(_)
        {
            
             aniDelay = 400;
             
             
            if(_.n > 0 ){
                nav.stop().animate({marginTop:'0px'}, 800, 'easeOutCubic');
                header.stop().animate({top:'0px'}, 800, 'easeOutCubic');
                content.css({display:'block'}).stop().animate({top:'-75px'}, 800, 'easeOutCubic');
            } else {
                nav.stop().delay(aniDelay/2).animate({marginTop:'40px'}, 900, 'easeOutCubic');
                header.stop().delay(aniDelay/2).animate({top:'160px'}, 900, 'easeOutCubic');
                content.stop().delay(aniDelay/2).animate({top:$(window).height()/2}, 800, 'easeOutCubic', function(){
                    $(this).css({display:'none'});
                });
            }
            
        
			if(_.curr){
		          if(_.n > 0 ){
    				_.curr
    					.stop()
    					.delay(aniDelay).css({display:'block'}).animate({top:'0px'}, 450,'easeOutCubic');
                  }
            }
			if(_.prev){
				_.prev
					.stop()
					.animate({top:'510px'}, 400,'easeInSine', function(){
					     $(this).css({display:'none'});
					})
            }
		}
	})
    
    var footerMenu = $('#footerMenu li')
        
    nav.navs(function(n, _){
		content.tabs(n);
        
        footerMenu.find('a').removeClass('active')
        if(_.n > -1){
            footerMenu.eq(_.n).find('a').addClass('active')
        }
        
        _.li.each(function(){
            if($(this).index() != _.pren){
                $(this).find('>a span').stop().animate({fontSize:'29px'}, 0 );
            }
            if($(this).hasClass('active')){
                $(this).find('>a span').stop().animate({color:'#000'}, 0 );
                if(!ie){
                    $(this).find('>a b').stop().animate({scale:1}, 0);
                } else {
                    $(this).find('>a b').stop().animate({ opacity:1}, 0);
                }
            }
        
        })
	})
		 
})